@extends('admin.layout')

@section('title', '创建分类')
@section('page-title', '创建分类')

@section('content')
<div class="space-y-6">
    <!-- 返回按钮 -->
    <div class="flex items-center">
        <a href="{{ route('admin.categories.index') }}" 
           class="inline-flex items-center text-sm font-medium text-gray-500 hover:text-gray-700">
            <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"></path>
            </svg>
            返回分类列表
        </a>
    </div>

    <!-- 添加分类表单 -->   
    <div class="bg-white shadow-lg rounded-xl border border-gray-100">
        <div class="px-6 py-6 border-b border-gray-200">
            <div class="flex items-center">
                <svg class="w-6 h-6 text-indigo-600 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"></path>
                </svg>
                <h1 class="text-xl font-semibold text-gray-900">创建新分类</h1>
            </div>
            <p class="mt-2 text-sm text-gray-600">填写分类信息来创建一个新的菜品分类</p>
        </div>

        <form method="POST" action="{{ route('admin.categories.store') }}" class="px-6 py-6">
            @csrf
            
            <div class="grid grid-cols-1 gap-6 sm:grid-cols-2">
                <!-- 分类名称 -->
                <div class="sm:col-span-2">
                    <label for="name" class="block text-sm font-medium text-gray-700">
                        分类名称 <span class="text-red-500">*</span>
                    </label>
                    <div class="mt-1">
                        <input type="text" 
                               name="name" 
                               id="name" 
                               value="{{ old('name') }}"
                               required
                               placeholder="例如：热菜、凉菜、汤品等"
                               class="block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm @error('name') border-red-300 @enderror">
                    </div>
                    @error('name')
                        <p class="mt-1 text-sm text-red-600">{{ $message }}</p>
                    @enderror
                </div>

                <!-- 分类标识 -->
                <div>
                    <label for="slug" class="block text-sm font-medium text-gray-700">
                        分类标识 <span class="text-red-500">*</span>
                    </label>
                    <div class="mt-1">
                        <input type="text" 
                               name="slug" 
                               id="slug" 
                               value="{{ old('slug') }}"
                               required
                               placeholder="例如：hot-dishes、cold-dishes等"
                               class="block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm @error('slug') border-red-300 @enderror">
                    </div>
                    <p class="mt-1 text-sm text-gray-500">用于URL和API的唯一标识，建议使用英文和连字符</p>
                    @error('slug')
                        <p class="mt-1 text-sm text-red-600">{{ $message }}</p>
                    @enderror
                </div>

                <!-- 分类描述 -->
                <div>
                    <label for="description" class="block text-sm font-medium text-gray-700">
                        分类描述
                    </label>
                    <div class="mt-1">
                        <textarea name="description" 
                                  id="description" 
                                  rows="4"
                                  placeholder="描述这个分类的特点和用途..."
                                  class="block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm @error('description') border-red-300 @enderror">{{ old('description') }}</textarea>
                    </div>
                    @error('description')
                        <p class="mt-1 text-sm text-red-600">{{ $message }}</p>
                    @enderror
                </div>

                <!-- 排序权重 -->
                <div>
                    <label for="sort_order" class="block text-sm font-medium text-gray-700">
                        排序权重
                    </label>
                    <div class="mt-1">
                        <input type="number" 
                               name="sort_order" 
                               id="sort_order" 
                               value="{{ old('sort_order', 0) }}"
                               min="0"
                               placeholder="数字越小排序越靠前"
                               class="block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm @error('sort_order') border-red-300 @enderror">
                    </div>
                    <p class="mt-1 text-sm text-gray-500">用于控制分类在列表中的显示顺序</p>
                    @error('sort_order')
                        <p class="mt-1 text-sm text-red-600">{{ $message }}</p>
                    @enderror
                </div>

                <!-- 启用状态 -->
                <div>
                    <div class="flex items-center">
                        <input type="checkbox" 
                               name="is_active" 
                               id="is_active" 
                               value="1"
                               {{ old('is_active', true) ? 'checked' : '' }}
                               class="h-4 w-4 text-indigo-600 focus:ring-indigo-500 border-gray-300 rounded">
                        <label for="is_active" class="ml-3 block text-sm font-medium text-gray-700">
                            启用此分类
                        </label>
                    </div>
                    <p class="mt-2 text-sm text-gray-500">禁用的分类不会在前端显示</p>
                </div>
            </div>

            <div class="flex justify-end space-x-3 mt-6">
                <a href="{{ route('admin.categories.index') }}" 
                   class="px-4 py-2 border border-gray-300 rounded-md text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
                    取消
                </a>
                <button type="submit" 
                        class="px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
                    创建分类
                </button>
            </div>
        </form>
    </div>
</div>
@endsection
